package nacos.example.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.Objects;

@Getter
@Setter
@Configuration
@ConfigurationProperties(prefix = "spring.cloud.nacos.config")
public class CustomNacosConfig {

    @Value("${spring.cloud.nacos.config.data-id:${spring.application.name}.${spring.cloud.nacos.config.file-extension:properties}}")
    private String dataId;

    private String group;
    private String namespace;
    @Value("${spring.cloud.nacos.config.file-extension:properties}")
    private String fileExtension;

    private boolean refreshEnabled= true;

    public List<Config> extensionConfigs;


    @Getter
    @Setter
    public static class Config {


        /**
         * the data id of extended configuration.
         */
        private String dataId;

        /**
         * the group of extended configuration, the default value is DEFAULT_GROUP.
         */
        private String group = "DEFAULT_GROUP";

        /**
         * whether to support dynamic refresh, the default does not support .
         */
        private boolean refresh = false;


        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }
            CustomNacosConfig.Config config = (CustomNacosConfig.Config) o;
            return refresh == config.refresh && Objects.equals(dataId, config.dataId)
                    && Objects.equals(group, config.group);
        }

        @Override
        public int hashCode() {
            return Objects.hash(dataId, group, refresh);
        }

    }
}
